package com.ahu.qifei.fenghuolun.task;

import com.ahu.qifei.common.service.IMailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @author ShiQifei
 * @date 2020/11/21 16:51
 */
@Configuration
@EnableScheduling
@Slf4j
public class WeeklyNewspaperTask {

    @Autowired
    @Qualifier("yundaMailSerivceImpl")
    IMailService mailService;

    private static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    private static final DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    // 收件者
    private static final String[] MAIL_RECEIVER = new String[]{
            "sunlingfeng2824@yundasys.com"
            ,"sunyubing2889@yundasys.com"
            ,"libotao8748@yundasys.com"
            , "qianyun2788@yundasys.com"

//            "714367321@qq.com",
//            "shiqifei2929@yundasys.com"
        };
    // 周五12点发送
//    @Scheduled(cron="0 0 18 ? * FRI")
    public void  analyseFund() {
        String todayDate = LocalDate.now().format(dtf);
        String fromDate = LocalDate.now().minusDays(4).format(dtf);
        StringBuffer subject = new StringBuffer("周报 ").append(fromDate).append("~").append(todayDate);
        String content =
                "本周工作：</br>" +
                "1. 完成商家小程序版本接口开发；</br>" +
                "2. 完成商家小程序前端联调工作；</br>" +
                "3. 完成商家小程序版本bug修复；</br>" +
                "----------------------------------------</br>" +
                "下周工作计划：</br>" +
                "1. 开发推送绑定后的信息给青鸟。</br>" +
                "2. 待安排计划进行任务分配。</br>" +
                "<hr style=\"WIDTH: 210px; HEIGHT: 1px\" color=\"#b5c4df\" size=\"1\" align=\"left\"></br>" +
                "shiqifei2929@yundasys.com";
        mailService.sendMimeMessage(MAIL_RECEIVER, subject.toString(), content);
        log.info("周报发送成功！");

    }
}
